write.admb.dat.fn <- function(start_year =1920, end_year =1959, n_intrvls_per_yr = 12, fishery_intervals =1, 
	survey_intervals = c(rep(1,3),rep(0,9)), max_age = 40, fish_dat, survey_dat, N0_phase = 1, F_phase = 1, q_phase = 1,
	fishery_sel_phase = 2, survey_sel_phase = 2, M_phase = -1, dat.file = 'tm.dat'){

	n_yrs <- end_year - start_year + 1
	
	write('# start year', file = dat.file)
	write(start_year, file = dat.file, append = T)
	write('# end year', file = dat.file, append = T)
	write(end_year, file = dat.file, append = T)
	write('# number of intervals per year', file = dat.file, append = T)
	write(n_intrvls_per_yr, file = dat.file, append = T)
	write('# fishery sampling probabilities by interval', file = dat.file, append = T)
	write.table(matrix(fishery_intervals, nrow = n_yrs, ncol = n_intrvls_per_yr, byrow = T), file = dat.file, append = T, 
		col.names = F, row.names = F)
	write('# survey sampling probabilities by interval', file = dat.file, append = T)
	write.table(matrix(survey_intervals,nrow = n_yrs, ncol = n_intrvls_per_yr, byrow = T), file = dat.file, append = T, 
		col.names = F, row.names = F)
	write('# survey effort by interval', file = dat.file, append = T)
	write.table(matrix(survey_intervals,nrow = n_yrs, ncol = n_intrvls_per_yr, byrow = T), file = dat.file, append = T, 
		col.names = F, row.names = F)
	write('# maximum age', file = dat.file, append = T)
	write(max_age, file = dat.file, append = T)
	write('# number of fishery observations', file = dat.file, append = T)
	write(dim(fish_dat)[1], file = dat.file, append = T)
	write('# fishery data', file = dat.file, append = T)
	write.table(fish_dat, file = dat.file, append = T, 
		col.names = F, row.names = F)
	write('# number of survey observations', file = dat.file, append = T)
	write(dim(survey_dat)[1], file = dat.file, append = T)
	write('# survey data', file = dat.file, append = T)
	write.table(survey_dat, file = dat.file, append = T, 
		col.names = F, row.names = F)
	write('# N0 phase', file = dat.file, append = T)
	write(N0_phase, file = dat.file, append = T)
	write('# F phase', file = dat.file, append = T)
	write(F_phase, file = dat.file, append = T)
	write('# q phase', file = dat.file, append = T)
	write(q_phase, file = dat.file, append = T)
	write('# fishery selectivity phase', file = dat.file, append = T)
	write(fishery_sel_phase, file = dat.file, append = T)
	write('# survey selectivity phase', file = dat.file, append = T)
	write(survey_sel_phase, file = dat.file, append = T)
	write('# M phase', file = dat.file, append = T)
	write(M_phase, file = dat.file, append = T)

}
